# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html

import pymongo
from items import JipiaoItem
import datetime



class JipiaoPipeline(object):
    def __init__(self):
        clinet = pymongo.MongoClient("localhost", 27017)
        db = clinet["Jipiao"]
        self.Information = db["Information"]


    def process_item(self, item, spider):
        """ 判断item的类型，并作相应的处理，再入数据库 """
        if isinstance(item, JipiaoItem):
            try:
                now = datetime.datetime.now()
                crawltime=item['crawltime']
                ret1=self.Information.find(({'crawltime':now.strftime('%Y-%m-%d %H:%M:%S') }))
                self.Information.insert(dict(item))
            except Exception:
                pass



